<template>
	<view>
		<view class="sort">
			<view class="sort_list">
				<view :class="filtrate_key == 0?'sort_list_boxs':'sort_list_box'" @click="filtrate_tap(0)">综合</view>
				<view :class="filtrate_key == 1?'sort_list_boxs':'sort_list_box'" @click="filtrate_tap(1)">销量</view>
				<view :class="filtrate_key == 2?'sort_list_boxs':'sort_list_box'" @click="filtrate_tap(2)">推荐</view>
				<view :class="filtrate_key == 3?'sort_list_boxs':'sort_list_box'" @click="filtrate_tap(3)">新品</view>
			</view>
		</view>
		<view class="search">
			<view class="searchs">
				<uni-easyinput prefixIcon="search" @confirm="iconClick" v-model="value" placeholder="请输入搜索关键词" @iconClick="iconClick" confirm-type="search"></uni-easyinput>
			</view>
		</view>
		<view class="list">
			<view class="list_all">
				<view class="list_box" v-for="(item,index) in goods_list" :key="index"
					@click="shop_details(item.goods_id)" style="background: #fff;">
					<image class="list_box_image" mode="aspectFill" :src="item.image"></image>
					<view class="list_box_title">{{item.name}}</view>
					<!-- <view class="list_box_titles">￥{{item.price}}</view> -->
					<view class="list_box_titles">积分{{item.price}}</view>
				</view>
				<view class="AllBottom" v-if="goods_list.length == 0">暂无更多数据</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_list:[],
				page:1,
				banner_list:[],
				filtrate_key:0,
				value:'',
			}
		},
		onShow() {
			this.page = 1
			this.goods_index_api()
			this.banner_index_api()
		},
		methods: {
			iconClick(type) {
				console.log('111',this.value)
				this.page = 1
				this.goods_index_api()
			},
			filtrate_tap(num) {
				this.filtrate_key = num
				this.page = 1
				this.goods_index_api()
			},
			//详情
			shop_details(goods_id) {
				uni.navigateTo({
					// url: '../shop_details/shop_details?goods_id=' + goods_id + '&key=1'
					url: '../shop_details/shop_details?goods_id=' + goods_id + '&key=3'
				})
			},
			//加盟
			goods_index_api() {
				var that = this
				that.$request(that.$Api.goods_index_api, {
					access_token: uni.getStorageSync('access_token'),
					sort:that.filtrate_key,
					keyword:that.value,
				}, "POST").then(res => {
					if (res.data.code == 0) {
						that.goods_list = res.data.data.list
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
		},
		onReachBottom() {
			var that = this
			that.page++
			that.$request(that.$Api.goods_index_api, {
				access_token: uni.getStorageSync('access_token'),
				page:that.page,
			}, "POST").then(res => {
				if (res.data.code == 0) {
					if( res.data.data.list.length != 0 ) {
						that.goods_list.concat(res.data.data.list)
					}else{
						uni.showToast({
							title: '暂无更多',
							duration: 2000,
							icon: 'none'
						});
					}
				} else {
					uni.showToast({
						title: res.data.msg,
						duration: 2000,
						icon: 'none'
					});
				}
			})
		}
	}
</script>

<style lang="less">
	page{
		background: #fff;
	}
	.search{
		.searchs{
			width: 700upx;
			border-radius: 30upx;
			margin-left: 25upx;
		};
		margin-top: 10upx;
		width: 750upx;
		padding: 0 0 20upx 0;
		border-bottom: 1upx solid #eee;
	}
	.sort{
		.sort_list{
			display: flex;
			justify-content: space-around;
			width: 750upx;
			.sort_list_box{
				font-size: 30upx;
				font-weight: bold;
			}
			.sort_list_boxs{
				font-size: 30upx;
				color: #cf4052;
				font-weight: bold;
			}
		}
		width: 750upx;
		padding: 20upx 0;
	}
	.list {
		.AllBottom{
			width: 100%;
			line-height: 100upx;
			font-size: 26upx;
			color: #999;
			text-align: center;
		}
		.top {
			width: 750upx;
			// height: 500upx;
			padding: 25upx;
			margin-top: -30upx;
		
			.swiper {
				width: 700upx;
				height: 400upx;
				border-radius: 20upx;
			}
		}
		.list_all {
			.list_box {
				.list_box_titles {
					font-size: 28upx;
					font-weight: bold;
					color: #cf4052;
					line-height: 34upx;
					margin-top: 8upx;
				}
	
				.list_box_title {
					width: 330upx;
					// height: 42upx;
					font-size: 28upx;
					color: #333333;
					line-height: 34upx;
					margin-top: 18upx;
				}
	
				.list_box_image {
					width: 330upx;
					height: 330upx;
	
					image {
						background: #eee;
					}
				}
	
				width: 330upx;
				padding: 10upx;
				margin-top: 20upx;
				// padding-top: 16upx;
			}
	
			width: 700upx;
			display: flex;
			justify-content: space-between;
			flex-direction: row;
			flex-wrap: wrap;
			padding: 0 25upx;
			margin-top: 0upx;
		}
	
		width: 750upx;
	}
</style>
